#ifndef G3_LUA_MATERIAL_H
#define G3_LUA_MATERIAL_H

#include <string>
#include <vector>
#include "res/res_texture.h"
#include "material.h"
#include "res/res_shader_prog.h"
#include "lua_handler.h"

using namespace G3;

int tolua_materialscript_open (lua_State *LuaState);

class G3MS_Texture {
public:
    G3MS_Texture () {
        Filter = GTF_MIPMAP;
    }

    std::string Filename;
    TEXTURE_FILTER Filter;
};

extern string G3MS_Name;
extern COL4F G3MS_Ambient;
extern COL4F G3MS_Diffuse;
extern COL4F G3MS_Specular;
extern COL4F G3MS_Emission;
extern float G3MS_Shininess;
extern float G3MS_Reflectance;
extern std::vector<G3MS_Texture> G3MS_Textures;
extern SHADER_PROGRAM G3MS_ShaderProgram;

static void MS_SetAmbient (float r, float g, float b, float a) {
    G3MS_Ambient.r = r;
    G3MS_Ambient.g = g;
    G3MS_Ambient.b = b;
    G3MS_Ambient.a = a;
}

static void MS_SetDiffuse (float r, float g, float b, float a) {
    G3MS_Diffuse.r = r;
    G3MS_Diffuse.g = g;
    G3MS_Diffuse.b = b;
    G3MS_Diffuse.a = a;
}

static void MS_SetSpecular (float r, float g, float b, float a) {
    G3MS_Specular.r = r;
    G3MS_Specular.g = g;
    G3MS_Specular.b = b;
    G3MS_Specular.a = a;
}

static void MS_SetEmission (float r, float g, float b, float a) {
    G3MS_Emission.r = r;
    G3MS_Emission.g = g;
    G3MS_Emission.b = b;
    G3MS_Emission.a = a;
}

static void MS_AddTexture (const char *filename, TEXTURE_FILTER filter) {
    Assert (filename, "MS_AddTexture: Filename argument is a NULL pointer");

    G3MS_Texture tex;
    tex.Filename = std::string (filename);
    tex.Filter = filter;

    G3MS_Textures.push_back (tex);
}

static bool MS_AddVertexShader (const char *filename) {
    Assert (filename, "MS_AddShader: Filename argument is a NULL pointer");

    return G3MS_ShaderProgram.AttachShader ((string) filename, SP_VERTEX);
}

static bool MS_AddFragmentShader (const char *filename) {
    Assert (filename, "MS_AddShader: Filename argument is a NULL pointer");

    return G3MS_ShaderProgram.AttachShader ((string) filename, SP_FRAGMENT);
}

#endif

